<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="script.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="padraosite.css" media="all" rel="stylesheet" type="text/css" />
<title>CIEC - Portarias</title>
<style type="text/css">
<!--
body {
	background-color: #339933;
}
.style2 {
	font-family: Verdana, Arial;
	font-weight: bold;
}
.style3 {color: #FFFFFF}
.style5 {color: #0000FF}
.style6 {
	font-family: Verdana, Arial;
	font-size: 14px;
	font-weight: bold;
}
-->
</style></head>

<body>

<?php
include("funcoes.php");
include("conexao.php");
if($_GET){
	
	$idPortaria = $_GET['idPortaria'];
	$esc_id = $_GET['esc_id'];
	
	$sql = "SELECT * FROM portaria WHERE idPortaria={$idPortaria}";
	$query = mysql_query($sql) or die("Ooooooops ocorreu um erro ao buscar dados da portaria ".mysql_error());
	$dados = mysql_fetch_array($query) or die("Ooooooops ocorreu um erro ao armazenar dados da portaria ".mysql_error());
	
	$idPortaria = $dados['idPortaria'];
	$port_num = $dados['NumPortaria'];
	$data_portaria = $dados['DataPortaria'];
	$dodf_num = $dados['Dodf'];
	$data_dodf = $dados['DataDodf'];
	$pag_dodf = $dados['PagDodf'];
	$obs = $dados['Obs'];
	
?>
<form id="form1" name="form6" method="post" action="doAPortaria.php">
<input type="hidden" name="esc_id" value="<?php echo $esc_id; ?>" />
<input type="hidden" name="idPortaria" value="<?php echo $idPortaria; ?>" />
<table width="500" height="163" border="0" align="center">
    <tr>
      <th bgcolor="#FFFFFF" scope="row"><table width="470" height="74" border="0" align="center">
        <tr>
          <th bgcolor="#CCCCCC" scope="row"><table width="450" border="0" align="center">
              <tr>
                <th width="83" scope="row"><div align="left">Portaria n&ordm;</div></th>
                <td width="39"><div align="left">
                  <input name="port_num" type="text" id="port_num" value="<?php echo $port_num;?>" size="5" maxlength="5" />
                </div></td>
                <td width="38"><span class="escrita"><strong>Data:</strong></span></td>
                <td width="63"><div align="left">
                  <input name="data_portaria" type="text" id="data_portaria" onKeyPress="return digitos(event, this);" onKeyUp="Mascara('DATA',this,event);" value="<?php echo dataBR($data_portaria);?>" size="10" maxlength="10"/>
                </div></td>
                <td colspan="2">
                </td>
              </tr>
              <tr>
                <th scope="row"><div align="left">DODF n&ordm;:</div></th>
                <td><div align="left">
                  <input name="dodf_num" type="text" id="dodf_num" value="<?php echo $dodf_num;?>" size="5" maxlength="5" />
                </div></td>
                <td><span class="escrita"><strong>Data:</strong></span></td>
                <td><div align="left">
                  <input name="data_dodf" type="text" id="data_dodf" onKeyPress="return digitos(event, this);" onKeyUp="Mascara('DATA',this,event);" value="<?php echo dataBR($data_dodf);?>" size="10" maxlength="10"/>
                </div></td>
                <td width="73"><span class="style2">P&aacute;gina n&ordm;:</span></td>
                <td width="164"><div align="left">
                  <input name="pag_dodf" type="text" id="pag_dodf" value="<?php echo $pag_dodf;?>" size="5" maxlength="5" />
                </div></td>
              </tr>
              <tr>
                <th colspan="6" scope="row"><div align="left">Observa&ccedil;&otilde;es:</div></th>
              </tr>
              <tr>
                <th colspan="6" scope="row"><textarea name="obs" id="obs" cols="80" rows="5"><?php echo $obs;?>
</textarea></th>
              </tr>
          </table></th>
        </tr>
      </table></th>
    </tr>
  </table>
<table width="500" border="0" align="center">
  <tr>
    <th scope="row"><input type="submit" name="button" id="button" value="Salvar" /></th>
  </tr>
</table>
<p>&nbsp;</p>
<p>
<?php 
}
elseif ($_POST){
	
	$esc_id = $_POST['esc_id'];
	$idPortaria = $_POST['idPortaria'];
	$port_num = $_POST['port_num'];
	$dodf_num = $_POST['dodf_num'];
	$data_portaria = dataUS($_POST['data_portaria']);
	$data_dodf = dataUS($_POST['data_dodf']);
	$pag_dodf = $_POST['pag_dodf'];
	$obs = $_POST['obs'];
	
	$updateSQL = "UPDATE portaria SET NumPortaria={$port_num},
								DataPortaria='$data_portaria',
								DataDodf='$data_dodf',
								Dodf={$dodf_num},
								PagDodf={$pag_dodf},
								Obs='$obs' 
								WHERE idPortaria='$idPortaria'";
	
	$query = mysql_query($updateSQL) or die("Oooooooops Erro ao atualizar dados - ".mysql_error());
	$url = "doPortaria.php?esc_id={$esc_id}";
	
	echo "<h2 align=\"center\" class=\"style4\">Cadastro Atualizado com Sucesso!!!!!!</h2>";
	echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2 ; URL={$url}\">";
}
?>
<p align="center" class="style5"><span class="style4 style5 style6"><a href="dados.php?esc_id=<?php echo $esc_id;?>">Retornar ao Cadastro da Institui&ccedil;&atilde;o Educacional</a></span></p>
<p>&nbsp; </p>
</form>

</body>
</html>
